void * Malloc( unsigned int size ) {

  void * toRet = malloc( size );
  if ( ! toRet ) {
    perror("CLib :: Malloc ");
    exit(1);
  }
  return toRet;
}




static char * getLine(char * prompt) {

  int start_size = 16;
  char * buf = Malloc( start_size * sizeof(char) );
  printf("%s ", prompt);

  while ( 1 ) {
    int c = getchar();
    if ( c == EOF ) {
      return NULL;
    }
    if ( ! isspace(c) ) {
      ungetc( c, stdin );
      break;
    }
  }

  int idx = 0;
  while ( 1 ) {
    int c = getchar();
    if ( c == EOF || c == '\n' ) {
      buf[idx] = '\0';
      break;
    }
    buf[idx] = c;
    if ( idx == start_size - 1 ) { // Buffer full
      start_size *= 2;
      buf = realloc( buf, start_size );
      assert( buf );
    }
    idx ++;
  }

  return buf;
}

int readInt( char * prompt ) {
  int toRet;
  int numRead;
  do {
    char * input = getLine( prompt );
    if ( ! input ) {
      return -1;
    }
    printf("%s\n", input);
    numRead = sscanf( input, "%d", &toRet );
    free ( input );
  } while ( numRead != 1 );
  return toRet;
}
